using System;
using System.Text.RegularExpressions;
using Newtonsoft.Json;

namespace TimeMachine.Engine.Vcs
{
	public class SourcesSettings : ISourcesSettings
	{
		private Regex mergingCommitMessageRe;
		private Regex sourceFilenameRe;
		private Regex trunkRe;

		public string SourceFilenameRegex { get; set; }

		public string MergingCommitMessageRegex { get; set; }

		public string TrunkFilenameRegex { get; set; }

		#region ISourcesSettings Members

		[JsonIgnore]
		public Regex SourceFilenameRE
		{
			get { return sourceFilenameRe ?? (sourceFilenameRe = Create(SourceFilenameRegex)); }
		}

		[JsonIgnore]
		public Regex MergingCommitMessageRE
		{
			get { return mergingCommitMessageRe ?? (mergingCommitMessageRe = Create(MergingCommitMessageRegex)); }
		}

		[JsonIgnore]
		public Regex TrunkRE
		{
			get { return trunkRe ?? (trunkRe = Create(TrunkFilenameRegex)); }
		}


		#endregion

		private static Regex Create(string regex)
		{
			return new Regex(regex ?? ".*", RegexOptions.Compiled | RegexOptions.IgnoreCase);
		}
	}
}